package com.powernode.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.Media;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MultiModelConreoller {

    @Resource
    private ChatClient chatClient;



    @RequestMapping(value = "/ai/multi")
    public Object multi(String msg, String imageUrl) {

        //先构建一个userMessage ，里面传入的就是msg，和图片
        UserMessage userMessage = new UserMessage(msg, List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageUrl)));
        //调用chatClient的call方法，把userMessage传进去，完后在 指定一个gpt的模型
        ChatResponse response = chatClient.call(new Prompt(userMessage, OpenAiChatOptions.builder()
                .withModel(OpenAiApi.ChatModel.GPT_4_VISION_PREVIEW.getValue())
                .build()));

        System.out.println(response.getResult().getOutput());
        return response.getResult().getOutput().getContent();
    }
    }
